<form action="" class="form-horizontal" role="form">
  <foreach name="productGoods.attrHtml" key="attr_name" item="attr_list">
  <div class="form-group">
    <label class="col-sm-2 control-label">{$attr_name}</label>
    <div class="col-sm-6 attrs" t="t-l">
       {$attr_list}
    </div>
  </div>
  </foreach>
  <div class="form-group">
   <div class="col-sm-offset-2 col-sm-8">
     <a class="btn btn-default" onclick="javascript:history.go(-1)">返回上页</a>
     <a class="btn btn-default" onclick="self.location=document.referrer">返回上页并刷新</a>
     <input type="hidden" name="cat_id" value="{$cat_id}">
     <input type="hidden" name="id" value="{$productGoods.id}">
     <button type="submit" class="btn btn-primary submit" data-loading-txt="提交中，请稍后……" data-ajax-url="__CONTROLLER__/modifyPost">保存更改</button>
   </div>
  </div>
</form>

<style type="text/css">
  .attrs label {
    width: 145px;
  	height: 28px;
    margin-bottom: 10px;
  }
  .attr_input_name {
    width: 80px;
  	height: 28px;
  	margin-left:3px;
  }
</style>

<script type="text/javascript">
var attributeStandard = {$attributeStandard} || {};
var productId = {$productGoods.id};
(function($) {
	$(document).ready(function() {
		
		function onChecked(attrId) {
			var name;
			var valueId = $(this).val();
			try{
				var attrCfg = attributeStandard[productId][attrId][valueId];
				name = attrCfg['name'];
			}catch(e){
				name = $(this).parent().contents().eq(1).text();
			}
			$(this).parent().contents().eq(1).remove();
			$(this).after("<input class='attr_input_name' value='"+ name +"' name='"+ $(this).attr("name").replace("[value]", "[name]") +"'  />").next().keyup(function(){
				attributeStandard[productId] = attributeStandard[productId] || {};
				attributeStandard[productId][attrId] = attributeStandard[productId][attrId] || {};
				attributeStandard[productId][attrId][valueId] = attributeStandard[productId][attrId][valueId] || {};
				attributeStandard[productId][attrId][valueId]['name'] = $(this).val();
			});
		}
		
		$("div[t='t-l']").each(function(i, o) {
			var attrId = $(o).find("input[t='attr_id']").val();
			var isStandard = $(o).find("input[t='is_standard']").val()*1;
			var isMultiselect = $(o).find("input[t='is_multiselect']").val()*1;
			if(isStandard) {
				$(o).delegate("input[type='checkbox']", "click", function() {
					if(!$(this).get(0).checked) {
						var name = $(this).parent().attr("title");
						$(this).next().remove();
						$(this).after(name);
					}else{
						onChecked.apply(this, [attrId]);
					}
				});
				$(o).delegate("input[type='radio']", "click", function() {
					var _this = $(this);
					$(this).parent().parent().find("input[type='radio']").each(function(){
						if(_this.attr('id') != $(this).attr('id')) {
							if($(this).next().is('input')) {
								var name = $(this).parent().attr("title");
								$(this).next().remove();
								$(this).after(name);
							}
						}
					});
					onChecked.apply(_this, [attrId]);
				});
				$("input[type='"+(isMultiselect?"checkbox":"radio")+"']", o).each(function() {
					if($(this).is(':checked')) onChecked.apply(this, [attrId]);
				});
			}
		});
	});
})(jQuery);
</script>